#region Using Statements
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace MyFirstXNAGame.Source.Sprites
{
    class Mario : Sprite
    {
        public Mario()
        {
            init();
            this.velocity = new Vector2(random.Next(250, 350), 0);
            this.color = Color.White;
            this.bounds.X = 360;
            this.bounds.Y = 240;
            this.bounds.Width = 50;
            this.bounds.Height = 59;
            this.numFrames = 6;
            this.levelOrigin.X = 245 * 32;
            this.levelOrigin.Y = 300;
            acceleration.Y = 2500.0f; //gravity
            this.scale = 1.5f;
        }
        public override Rectangle getBounds()
        {
            return bounds;
        }
        public override void onCollission(Sprite other)
        {

        }
        public override bool update(float xOrigin, float yOrigin, int width, int height, GameTime gameTime, ArrayList environment, Vector2 theOrigin)
        {
            float xMin = theOrigin.X;
            float yMin = theOrigin.Y;
            animate(gameTime.TotalGameTime.Milliseconds);
            accelerate(gameTime);
            accelerateX = true;
            accelerateY = true;
            Sprite collisionSprite;
            Vector2 movement = velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            updateX(xOrigin, width, gameTime, movement, xMin);
            collisionSprite = detectCollisions(environment);
            if (collisionSprite != null)
            {
                if (movement.X > 0)
                {
                    levelOrigin.X = collisionSprite.levelOrigin.X - getBounds().Width;
                    bounds.X = collisionSprite.getBounds().X - getBounds().Width;
                }
                else if (movement.X < 0)
                {
                    levelOrigin.X = collisionSprite.levelOrigin.X + collisionSprite.getBounds().Width;
                    bounds.X = collisionSprite.getBounds().X + collisionSprite.getBounds().Width;
                }
                velocity.X *= -1;
            }
            updateY(yOrigin, width, gameTime, movement, yMin);
            collisionSprite = detectCollisions(environment);
            if (collisionSprite != null)
            {
                if (movement.Y > 0)
                {
                    levelOrigin.Y = collisionSprite.levelOrigin.Y - getBounds().Height;
                    bounds.Y = collisionSprite.getBounds().Y - getBounds().Height;
                    velocity.Y = 0;
                }
                else if (movement.Y < 0)
                {
                    levelOrigin.Y = collisionSprite.levelOrigin.Y + collisionSprite.getBounds().Height;
                    bounds.Y = collisionSprite.getBounds().Y + collisionSprite.getBounds().Height;
                    velocity.Y = .01f;
                }
            }
            return true;
        }
        public override void input()
        {

        }
        public override ArrayList getCollisionBox()
        {
            return getDefaultCollisionBox();
        }
    }
}
